package com.example.booksystem.biz;

import com.example.booksystem.bean.Book;
import com.example.booksystem.bean.Type;
import com.example.booksystem.dao.BookDao;
import com.example.booksystem.dao.TypeDao;

import java.util.List;

public class TypeBiz {
    TypeDao typeDao = new TypeDao();
    public int add(String name,long parentId) {
        return typeDao.add(name,parentId);
    }

    public int modify(long id,String name,long parentId){
        return typeDao.modify(id,name,parentId);
    }

    public int remove(long id) throws Exception {
        BookDao bookDao = new BookDao();
        List<Book> books = bookDao.getBooksByTypeId(id);
        if (books.size()>0){
            throw new Exception("删除的类型有子信息,删除失败");
        }
        return typeDao.remove(id);
    }

    public List<Type> getAll(){
        return typeDao.getAll();
    }

    public Type getById(long id){
        return typeDao.getById(id);
    }
}
